package cemp.controller;


import cemp.common.dto.Response;
import cemp.common.dto.request.StockLoginRequestDto;
import cemp.common.dto.request.StockSysUserRequestDto;
import cemp.service.StockCoreService;
import cemp.service.StockSysUserService;
import com.alibaba.cloud.commons.lang.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;


@RestController
@AllArgsConstructor
@RequestMapping("/shiro")
public class SysUserController {

    @Autowired
    StockSysUserService stockSysUserService;

    @GetMapping("/test")
    public String list() {
        System.out.println("test");
        return "test";
    }


    //注册
    @PostMapping("/register")
    public void register(@RequestBody StockSysUserRequestDto sysuser) throws InvocationTargetException, IllegalAccessException {
        stockSysUserService.register(sysuser);
    }


    //登录
    @PostMapping("/login")
    public Response<String> login(@RequestBody StockLoginRequestDto login) throws Exception {
        String token = stockSysUserService.login(login);
        if(StringUtils.isNotBlank(token)){
            return Response.success(token);
        }else{
            return Response.error("500","登录失败");
        }
    }
}
